package com.alks.function.mapper;

import com.alks.entity.data.entity.*;
import com.alks.function.data.request.operate.material.*;
import com.alks.function.data.request.operate.materialIn.MtlBIStorageReq;
import com.alks.function.data.request.stock.InventoryLocFil;
import com.alks.function.data.request.stock.PcMtlStockRequest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
public interface PcMtlStockMapper extends BaseMapper<PcMtlStock> {
    List<PcMtlStock> pcMtlStockList(PcMtlStockRequest request);

    Long pcMtlStockTotal(PcMtlStockRequest request);

    List<PcMtlStockIn> pcMtlStockIn(@Param("mtlNo") String mtlNo);

    Long pcMtlStockInTotal(@Param("mtlNo") String mtlNo);

    List<PcMtlStockOut> pcMtlStockOut(@Param("mtlNo") String mtlNo);

    Long pcMtlStockOutTotal(@Param("mtlNo") String mtlNo);

    BigDecimal getStocks(PcMtlStockRequest request);

    List<Map<String, String>> pcMtlStockCondition();

    List<InventoryLocFil> wareHouseList(InventoryLocFil request);

    void insertHouse(@Param("request") InventoryLocFil request,@Param("username") String username);

    List<MtlBIStorageRep> mtlBIStorageList(MtlBIStorageReq req);

    BigDecimal mtlBIStorageInTotal(MtlBIStorageReq req);

    @Delete("DELETE FROM PC_MTL_IN WHERE SLIP_NO = #{slipNo} AND ORDER_ID = #{lotNo} AND MTL_COLOR = #{mtlColor} AND MTL_NAME = #{mtlName} AND IN_QTY = #{inQty} AND PUR_NO = #{purNo} LIMIT 1")
    int deleteBIStorage(MtlBIStorageRep req);

    List<SdMtlNewKfRep> chooseMtlInList(MaterialOtherChoReq req);

    int insertIntoTemp(@Param("list") List<SdMtlNewKfRep> list,@Param("username") String username);

    List<SdMtlOtherTempRep> mtlOtherList(String name);

    @Select("SELECT TYPE_NO,TYPE_NAME FROM SD_MTL_TYPE_NEW")
    Set<Map<String, String>> getSdmtl();

    int deleteByTemp(@Param("name") String name);

    List<SdMtlOtherTempDetailRep> mtlDetailList(MaterialOtherDetailReq req);

    int cOtherDetailList(@Param("rep") CreMtlOtherDetailReq req,@Param("name") String name,@Param("slipNo") String slipNo);

    int dOtherDetail(SdMtlOtherTempDetailRep req);

    void deleteHouse(InventoryLocFil request);

    @Select("SELECT ORDER_ID LOT_NO,SLIP_NO,SLIP_DATE,MTL_NAME,MTL_COLOR,MTL_SPEC,MTL_UNIT,CAST(OUT_QTY AS DECIMAL(10,2)) OUT_QTY,AREA_NO,REMARK FROM PC_MTL_OUT ORDER BY SLIP_NO DESC")
    List<PcMtlOut1Rep> outMtlList();

    @Select("SELECT CAST(SUM(OUT_QTY) AS DECIMAL(10,2)) FROM PC_MTL_OUT")
    BigDecimal outMtlListOutQtyTotal();

    List<PcMtlOtherOut2Rep> chooseMtlOtherList(MaterialOtherChoReq req);

    Integer otherMtlOuts(@Param("req") List<PcMtlOtherOut2Rep> req,@Param("name") String name);

    List<OtherMtlDetailOutRep> otherMtlDetailList(String name);

    Integer creOtherMtlSlip(@Param("req")OtherMtlDetailOutListReq req,@Param("slipNo") String slipNo,@Param("name") String name);

    Integer reduceStock(OtherMtlDetailOutListReq req);

    List<MtlOtherDetailOut1Rep> otherDetails(MtlOther2Req req);

    @Delete("DELETE FROM PC_MTL_OTHER WHERE ORDER_ID = #{lotNo} AND SLIP_NO = #{slipNo} AND MTL_NO = #{mtlNo} AND QTY = #{outQty} LIMIT 1")
    Integer deleteByOtherDetail(MtlOtherDetailOut1Rep rep);

    @Select("select count(*) from PC_MTL_IN where pur_no = #{slipNo}")
    Integer getBySlipNo(String slipNo);

    void insertIntoPcScanTemp(@Param("slipNo") String slipNo, @Param("name") String name);

    List<ScanTheDocumentInformation> getScanInSlipTemp(String username);

    void deleteByTempList(@Param("loginName") String loginName, @Param("list") List<ScanTheDocumentInformation> list);

    void insetIntoPcMtlIn(@Param("list") List<ScanTheDocumentInformation> list, @Param("name") String name);

    void updatePcMtlStock(@Param("re") ScanTheDocumentInformation re);

    Integer getMtlByStock(ScanTheDocumentInformation req);

    void insertIntoPcMtlStock( ScanTheDocumentInformation req);

    void updatePcMtlIn(@Param("sendNos") List<String> sendNos);

    @Select("select count(*) from PC_MTL_PRE_OTHER where pur_no = #{slipNo}")
    Integer getSlipByPre(String slipNo);

    Integer scanSlipByLotNo(@Param("name") String name, @Param("lotNo") String lotNo);

    List<ScanOutDetail> getScanSlipByLotNo(@Param("loginName") String loginName);

    ScanOutDetail getPcPurDetail(String lotNo);

    void createOutSlipNo(@Param("list") List<ScanOutDetail> list, @Param("slipNo") String slipNo, @Param("name") String name);

    void updateDPcMtlStock(@Param("scan") ScanOutDetail scan);

    Integer getPreSlipSize(@Param("slipNo") String slipNo);
}
